import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalMyCoinPage(Base):
    """
    我的积分页
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # `我的积分`标题
        self.coin_title_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_car_coin_title"))

        # 我的积分总数
        self.coin_total_coins_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_total_car_coin"))

        # 积分页列表任务标题, 默认取1
        self.coin_list_task_title_text = (By.XPATH, Personal.coin_list_task_title_text.format(1))

        # 积分页列表完成时间标题
        self.coin_list_task_time_text = (By.XPATH, Personal.coin_list_task_time_text.format(1))

        # 积分页列表车币数量变化标题
        self.coin_list_task_count_text = (By.XPATH, Personal.coin_list_task_count_text.format(1))

        # 积分页列表车币icon
        self.coin_list_task_coin_icon = (By.XPATH, Personal.coin_list_task_coin_icon.format(1))

    def get_title(self):
        """
        获取顶部标题 `我的积分`

        :return:
        """
        return self.find_element_o(self.coin_title_text)

    def get_total_coins(self):
        """
        获取用户积分总量

        :return:
        """
        return self.find_element_o(self.coin_total_coins_text)

    def get_list_task_title(self, index=1):
        """
        获取右侧积分记录的任务标题

        :param index: 索引值
        :return:
        """
        self.coin_list_task_title_text = (By.XPATH, Personal.coin_list_task_title_text.format(index))
        return self.find_element_o(self.coin_list_task_title_text)

    def get_list_task_time(self, index=1):
        """
        获取右侧积分记录的完成时间

        :param index: 索引值
        :return:
        """
        self.coin_list_task_time_text = (By.XPATH, Personal.coin_list_task_time_text.format(index))
        return self.find_element_o(self.coin_list_task_time_text)

    def get_list_task_count(self, index=1):
        """
        获取右侧积分记录的车币变化数量

        :param index: 索引值
        :return:
        """
        self.coin_list_task_count_text = (By.XPATH, Personal.coin_list_task_count_text.format(index))
        return self.find_element_o(self.coin_list_task_count_text)

    def get_list_task_coin(self, index=1):
        """
        获取右侧积分记录的车币icon

        :param index: 索引值
        :return:
        """
        self.coin_list_task_coin_icon = (By.XPATH, Personal.coin_list_task_coin_icon.format(index))
        return self.find_element_o(self.coin_list_task_coin_icon)
